// userInfo
import { UserProfilesAPI } from '@/request/api'

export default {
  namespaced: true,
  state: {
    // 用户信息
    userInfo: {
      // 昵称
      nickName: '游客',
      // 鸡腿数
      coin: 0,
      // 头像
      headImg: require('@/assets/images/userImg.f8bbec5e.png')
    },
    // 购物车总数
    cartTotal: 0
  },
  mutations: {
    // 修改登录状态的方法
    changeUserInfo(state, payload) {
      state.userInfo = payload.userInfo
      state.cartTotal = payload.cartTotal
    },
    initUserInfo(state) {
      state.userInfo = {
        nickName: '游客',
        coin: 0,
        headImg: require('@/assets/images/userImg.f8bbec5e.png')
      }
      state.cartTotal = 0
    }
  },
  actions: {
    async asyncChangeUserInfo({ commit }) {
      let users = await UserProfilesAPI()
      commit('changeUserInfo', users.data)
    }
  }
}
